/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package listener;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import javax.servlet.ServletContextEvent;
import module.MyModule;
import module.MyServletModule;

/**
 *
 * @author think
 */
public class MyGuiceServletConfig extends GuiceServletContextListener {
    public static final String KEY = Injector.class.getName();

    public void contextInitialized(ServletContextEvent sce) {
//        if (sce.getServletContext().getAttribute(KEY) != null) {
//            sce.getServletContext().removeAttribute(KEY);
            sce.getServletContext().setAttribute(KEY, getInjector());
        }
//    }

    public void contextDestroyed(ServletContextEvent sce) {
        sce.getServletContext().removeAttribute(KEY);
    }


	@Override
	protected Injector getInjector() {
//		return Guice.createInjector();
		return Guice.createInjector(new MyServletModule(), new MyModule());
	}

}
